<?php
$gmc= new GearmanClient();
$gmc->addServer();
$args1 = array("url"=>"http://list.iqiyi.com/www/2/------------2-1-2-1---.html","encode"=>"utf-8","reg"=>"/data-key=\"(\d+)\"/ims","cache"=>true);
//$args1 = array("url"=>"http://list.iqiyi.com/www/1/----------0--2-1-2-1---.html","encode"=>"utf-8","reg"=>"/<li>.*?href=\"([^\"]*)/ims","cache"=>true);
$workload1 = serialize($args1);
$issues = unserialize($gmc->do("urlresult", $workload1, NULL));
print_r($issues);
echo $issues[1][count($issues[1])-1];
$n = $issues[1][count($issues[1])-1];
$gmc->setCompleteCallback("_complete");
$result = array();
for($i=1;$i<=$n;$i++){
	echo $i;
	$args = array("url"=>"http://list.iqiyi.com/www/2/------------2-1-$i-1---.html","encode"=>"utf-8","reg"=>"/<li>.*?href=\"([^\"]*)/ims","cache"=>true);
        $workload = serialize($args);
        $gmc->addTask("urlresult", $workload, &$result);
}
/*
echo $issues[1][0];
$args2 = array("url"=>"http://caipiao.taobao.com/lottery/order/united_list.htm?_tb_token_=160bbeddd7b3&page=1&lottery_type=SSQ&sort_obj=process&sort=desc&change_sort=&chg_type=0&lowAmount=&highAmount=&maxPushTop=5&issue=".$issues[1][0]."&is_not_full=2&UnitedFee=0-0&creator=&commission_rate=-1","encode"=>"gbk","reg"=>"/共(\d*)页/ims");
$workload2 = serialize($args2);
$pages = unserialize($gmc->do("urlresult", $workload2, NULL));
$pageNum = $pages[1][0];
echo $pageNum;
$gmc->setCompleteCallback("_complete");
$result = array();
for($i=1;$i<=$pageNum;$i++){
	$args = array("url"=>"http://caipiao.taobao.com/lottery/order/united_list.htm?_tb_token_=000bbe11ef7b3&page=$i&lottery_type=SSQ&sort_obj=process&sort=desc&change_sort=&chg_type=0&lowAmount=&highAmount=&maxPushTop=5&issue=".$issues[1][0]."&is_not_full=2&UnitedFee=0-0&creator=&commission_rate=-1","encode"=>"gbk","reg"=>"/united_id=([^\"]*)/ims");
	$workload = serialize($args);
	$gmc->addTask("urlresult", $workload, &$result);
}*/
if (! $gmc->runTasks())
{
    echo "ERROR " . $gmc->error() . "\n";
    exit;
}
echo "DONE\n";
function _complete($task,&$result)
{
    echo "COMPLETE: " . $task->jobHandle() . ":\n";
    $r = unserialize($task->data());
    echo count($r[1])."\n";
    $result = array_merge($result,$r[1]);
}
$result = array_unique($result);
print_r($result);
echo count($result);
?>
